﻿@{
    ViewBag.PageTitle = Resources.Intercamber.TextManagement_PageName;
}
@section PageHead
{
    <script type="text/javascript">
        var lastSelRow = -1;
        $(function () {
            $(".jqbutton").button();
            $("#gridTexts").jqGrid({
                //autowidth: true,
                datatype: 'json',
                width: '100%',
                height: '100%',
                jsonReader: { 'repeatitems': false, 'id': 'Code' },
                loadonce: false,
                pager: 'gridTexts_pager',
                rowList: [10, 20, 50],
                rowNum: 20,
                url: '/Admin/TextsData?filter=' + $("#SearchText").val(),
                viewrecords: true,
                colModel: [
                    { name: "Code", width: 200, align: 'center', label: 'Code', editable: false },
                    @{
                        List<string> languages = ViewBag.AvailableLanguages;
                        foreach (string s in languages)
                        {
                            @Html.Raw("{ name: 'Text_" + s + "', width:200, editable: true, align: 'left', label: 'Text " + s + "', edittype: 'textarea', editoptions: { rows: '4', cols: '30'} },");
                        }
                    }
                ],
                subGrid: false,
                subGridOptions: { expandOnLoad: true, selectOnExpand: false, reloadOnExpand: false },
                loadComplete: function () {
                    //$("#gridDiscussions").jqGrid("hideCol", "subgrid");
                    $("#gridDiscussions").jqGrid('setGridWidth', 800, true);
                },
                onSelectRow: function (id) {
                    if (id && id !== lastSelRow) {
                        if (lastSelRow)
                            // save or restore currently editing row
                            $('#gridTexts').saveRow(lastSelRow);

                        $('#gridTexts').restoreRow(lastSelRow);
                        $('#gridTexts').editRow(id, true);
                        lastSelRow = id;
                    }
                },
                editurl: "/Admin/TextsEdit",
            }).trigger("reloadGrid", [{ page: 1 }]);
            
            $("#SearchText").keypress(function (e) {
                var key = window.event ? window.event.keyCode : e.which;
                if (key == 13) {
                    $("#gridTexts").jqGrid().setGridParam({
                        datatype: 'json',
                        url: '/Admin/TextsData?filter=' + $("#SearchText").val()
                    }).trigger("reloadGrid", [{ page: 1 }]);
                    return false;
                }
                return true;
            });
        });
    </script>
}

@section PageContent
{
    <div class="innerTitle ui-corner-all">
        @Resources.Intercamber.TextManagement_PageName
    </div>
    <div style="margin: 4px 0 8px 0">
        @Resources.Intercamber.TextManagement_Search
        <input type="text" id="SearchText" />
    </div>
    <table id='gridTexts' style="width: 100%"></table>
    <div id="gridTexts_pager"></div>
}
